'use strict';
exports.main = async (event, context) => {
  const db = uniCloud.database()
  
  try {
    // 获取当前用户ID
    const { OPENID, UNIONID, APPID } = context
    if (!OPENID) {
      return {
        code: 403,
        message: '未登录'
      }
    }
    
    const { petId } = event
    if (!petId) {
      return {
        code: 400,
        message: '缺少宠物ID'
      }
    }
    
    // 查询宠物的健康记录
    const records = await db.collection('health_records')
      .where({
        pet_id: petId,
        user_id: OPENID
      })
      .orderBy('date', 'desc')
      .get()
    
    return {
      code: 200,
      message: '获取成功',
      data: records.data
    }
    
  } catch (error) {
    console.error('获取健康记录失败:', error)
    return {
      code: 500,
      message: error.message || '获取失败'
    }
  }
} 